package s.k.gui.webtest.element.locator;

import java.util.HashMap;
import java.util.Map;

public class Locator {

	public Locator() {

	}

	private String CurrentLocator;

	public String getCurrentLocator() {

		return CurrentLocator;
	}

	public void setCurrentLocator(String CurrentLocator) {

		this.CurrentLocator = CurrentLocator;
	}

	/**
	 * @author Administrator
	 *         ÿһ��Ԫ�ض��ж�������ֵ������QTP��Ԫ�ض�λ��ʽ�����ж༶��λ��ͨ��
	 *         ༶��λ���ﵽԪ�ؼ�ʹ���ָ�������
	 *         �ܹ�����õ�֧�֣��ܹ���õĶ�λ������ֹ����г��ֶ�λ�?�µ�Ԫ�ض�λʧ�ܡ�
	 * 
	 */
	private Map<String, String> locators = new HashMap<String, String>();

	public void addIdLocator(String id) {

		locators.put("id", id);
	}

	public void addNameLocator(String name) {

		locators.put("name", name);
	}

	public void addXpathLocator(String xpath) {

		locators.put("xpath", xpath);
	}

	public void addCSSLocator(String css) {

		locators.put("css", css);
	}

	public void addLinkTextLocator(String linkText) {

		locators.put("linktext", linkText);
	}

	public void addPartialLinkTextLocator(String partialLinkText) {

		locators.put("partiallinktext", partialLinkText);

	}

	public void addTagNameLocator(String tagName) {

		locators.put("tagname", tagName);

	}

	public void addRegularLocator(String regular) {

		locators.put("regular", regular);

	}

	public void addAttributeLocator(String attributeName, String attributeValue) {

		locators.put(attributeName, attributeValue);

	}

	public void addClassLocator(String className) {

		locators.put("className", className);
	}

	/** ���locatorType���locator */
	public String getLocator(String locatorType) {

		return locators.get(locatorType);

	}

	public String getLocatorById() {

		return locators.get("id");

	}

	public String getLocatorByName() {

		return locators.get("name");

	}

	public String getLocatorByXpath() {

		return locators.get("xpath");

	}

	public String getLocatorByCSS() {

		return locators.get("css");
	}

	public String getLocatorByLinkText() {

		return locators.get("linktext");
	}

	public String getLocatorByPartialLinkText() {

		return locators.get("partiallinktext");
	}

	public String getLocatorByRegular() {

		return locators.get("regular");

	}

	public String getLocatorByTagName() {

		return locators.get("tagname");

	}

	public String getXpathFromTagName() {

		if (locators.get("tagname") != null)

			return ".//" + locators.get("tagname");

		return null;
	}

	public String getXpathFromId() {

		if (locators.get("id") != null)

			return ".//*[@id=\'" + locators.get("id") + "\']";

		return null;
	}

	public String getXpathFromName() {

		if (locators.get("name") != null)

			return ".//*[@name=\'" + locators.get("name") + "\']";

		return null;
	}

	public String getXpathFromLinkText() {

		if (locators.get("linktext") != null)

			return ".//*[text()=\'" + locators.get("linktext") + "\']";

		return null;
	}

	public String getXpathFromPartialLinkText() {

		if (locators.get("partiallinktext") != null)

			return ".//*[contains(text(),\'" + locators.get("partiallinktext")
					+ "\')]";

		return null;
	}
}
